home *** CD-ROM | disk | FTP | other *** search
- Path: news.mindspring.com!usenet
- From: rroberts@mindspring.com (Ryan Roberts)
- Newsgroups: comp.lang.c++
- Subject: Random number question....
- Date: Sat, 16 Mar 1996 15:31:16 GMT
- Organization: MindSpring Enterprises
- Message-ID: <4iemrd$iap@firebrick.mindspring.com>
- NNTP-Posting-Host: rroberts.mindspring.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Hello all, I'm _just_ getting starting programming and have bought
- all the books, but still have a question. Look at this code:
-
- #include <iostream.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- main()
- {
- int num;
- randomize;
- num = (rand() % 5 + 1);
- if (num==0) cout << "Random Number 1\n";
- if (num==1) cout << "Random Number 2\n";
- //etc.... down to Random Five
- return 0;
- }
-
- When I run this code it will disply more than one random number
- between 0-5. It display's like:
- Random Number 1
- Random Number 2
- etc....
-
- Can some tell me how to generate _one_ random number
- between 0-5 and it disaply one the string assoicated with that
- random number?
-
- Thanks!!
-
- rroberts@mindspring.com
-
-
-